<template>
  <el-dialog v-model="dialogVisible" title="导入问题清单" width="1000" :before-close="handleClose">
    <el-table :data="tableData" :max-height="tableMaxHeight">
      <el-table-column prop="name" label="姓名" />
      <el-table-column prop="mobile" label="联系方式" width="120" />
      <el-table-column prop="identityCard" label="身份证" width="170" />
      <el-table-column prop="email" label="邮箱" width="170" />
      <el-table-column prop="education" label="最高学历" width="130" />
      <el-table-column prop="graduationMajor" label="毕业专业" width="110" />
      <el-table-column prop="workYears" label="累计工作年限 " width="110" />
      <el-table-column prop="enterprise" label="所在企业名称" width="200" />
      <el-table-column prop="enterpriseTax" label="所在企业税号" width="200" />
      <el-table-column prop="enterpriseJurisdiction" label="所在企业区属" width="130" />
      <el-table-column label="学员标签" prop="tags" />
      <el-table-column label="学员来源" prop="studentSourceList" />
      <el-table-column label="错误原因" prop="errText" width="150" fixed="right" />
    </el-table>
    <template #footer>
      <div class="dialog-footer">
        <el-button @click="handleClose">取消</el-button>
        <el-button type="primary" @click="save" :loading="loading">
          导出
        </el-button>
      </div>
    </template>
  </el-dialog>
</template>

<script setup lang="ts">
import useCounterStore from "@/store/counter";
const counter = useCounterStore();
const instance = getCurrentInstance();
const { proxy } = getCurrentInstance();

let dialogVisible = ref(false);
let tableData = ref([]);
let loading = ref(false);

let tableMaxHeight = computed(() => {
  return `${window.innerHeight * 0.7}px`;
});

function open(list) {
  tableData.value = list;
  dialogVisible.value = true;
}

function handleClose() {
  tableData.value = [];
  dialogVisible.value = false;
}

async function save() {
  try {
    loading.value = true;
    let list = [];
    tableData.value.forEach((element) => {
      list.push({
        姓名: element.name,
        联系方式: element.mobile,
        身份证: element.identityCard,
        邮箱: element.email,
        最高学历: element.education,
        毕业专业: element.graduationMajor,
        累计工作年限: element.workYears,
        所在企业名称: element.enterprise,
        所在企业税号: element.enterpriseTax,
        所在企业区属: element.enterpriseJurisdiction,
        学员标签: element.tags,
        错误原因: element.errText,
        学员来源: element.studentSourceList,
      });
    });
    let cols = [{ wch: 15 }, { wch: 45 }]; //设置表头样式
    let query = {
      jsonData: list,
      cols,
    };
    await proxy.$utils.exportToExcel(query, "导入失败数据");
    handleClose();
  } catch (error) {
    console.log("导出失败", error);
  } finally {
    loading.value = false;
  }
}

defineExpose({ open });
</script>



<style lang="scss" scoped>
.container {
}
</style>



